package io.openmessaging;

public class 二分查找 {

    public static void main(String[] args) {
        int[] nums=new int[]{-1,0,3,5,8,12};
        int target=8;
        int start=0;

        int end=nums.length-1;

        while(start<=end){
            int mid = (end - start) / 2 + start;
            if(target>nums[mid]){
                start=mid+1;
                continue;
            }
            if(target<nums[mid]){
                end=mid-1;
                continue;
            }

            if(target==nums[mid]){
                System.out.println(mid);
                break;
            }

        }

            System.out.println("-1");
    }
}
